# Stats|Array.<FileStats> FileSystemManager.statSync(string path, boolean recursive)

以 Promise 风格调用:不支持

# 功能描述

FileSystemManager.stat 的同步版本

# 参数

# string path

文件/目录路径 (本地路径)

# boolean recursive

是否递归获取目录下的每个文件的 Stats 信息

# 返回值

# Stats|Array.<FileStats> stats

当 recursive 为 false 时,res.stats 是一个 Stats 对象。当 recursive 为 true 且 path 是一个目录的路径时,res.stats 是一个 Array,数组的每一项是一个对象,每个对象包含 path 和 stats。

# 错误

错误码错误信息说明
1300001operation not permitted操作不被允许(例如,filePath 预期传入一个文件而实际传入一个目录)
1300002no such file or directory ${path}文件/目录不存在,或者目标文件路径的上层目录不存在
1300005Input/output error输入输出流不可用
1300009bad file descriptor无效的文件描述符
1300013permission denied权限错误,文件是只读或只写
1300014Path permission denied传入的路径没有权限
1300020not a directorydirPath 指定路径不是目录,常见于指定的写入路径的上级路径为一个文件的情况
1300021Is a directory指定路径是一个目录
1300022Invalid argument无效参数,可以检查length或offset是否越界
1300036File name too long文件名过长
1300066directory not empty目录不为空
1300201system error系统接口调用失败
1300202the maximum size of the file storage limit is exceeded存储空间不足,或文件大小超出上限(上限100M)
1300203base64 encode error字符编码转换失败(例如 base64 格式错误)
1300300sdcard not mountedandroid sdcard 挂载失败
1300301unable to open as fileType无法以fileType打开文件
1301000permission denied, cannot access file path目标路径无访问权限(usr目录)
1301002data to write is empty写入数据为空
1301003illegal operation on a directory不可对目录进行此操作(例如,指定的 filePath 是一个已经存在的目录)
1301004illegal operation on a package directory不可对代码包目录进行此操作
1301005file already exists ${dirPath}已有同名文件或目录
1301006value of length is out of range传入的 length 不合法
1301007value of offset is out of range传入的 offset 不合法
1301009value of position is out of rangeposition值越界
1301100store directory is emptystore目录为空
1301102unzip open file fail压缩文件打开失败
1301103unzip entry fail解压单个文件失败
1301104unzip fail解压失败
1301111brotli decompress failbrotli解压失败(例如,指定的 compressionAlgorithm 与文件实际压缩格式不符)
1301112tempFilePath file not exist指定的 tempFilePath 找不到文件
1302001fail permission denied指定的 fd 路径没有读权限/没有写权限
1302002excced max concurrent fd limitfd数量已达上限
1302003invalid flag无效的flag
1302004permission denied when open using flag无法使用flag标志打开文件
1302005array buffer does not exist未传入arrayBuffer
1302100array buffer is readonlyarrayBuffer只读

# 示例代码

recursive 为 false 时

// 异步版本
let fs = tap.getFileSystemManager()
fs.stat({
  path: `${tap.env.USER_DATA_PATH}/testDir`,
  success: res => {
    console.log(res.stats.isDirectory())
  }
})
// 同步版本
fs.statSync(`${tap.env.USER_DATA_PATH}/testDir`, false)

recursive 为 true 时

let fs = tap.getFileSystemManager()
// 异步版本
fs.stat({
  path: `${tap.env.USER_DATA_PATH}/testDir`,
  recursive: true,
  success: res => {
    Object.keys(res.stats).forEach(path => {
      let stats = res.stats[path]
      console.log(path, stats.isDirectory())
    })
  }
})
// 同步版本
fs.statSync(`${tap.env.USER_DATA_PATH}/testDir`, true)